#include <bits/stdc++.h>
// 2025/02/07
// tag: 
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

int t, maxp, w, ap, bp, as, bs, dp[2001][2001];

void DynalmicProgramming(int x){
    deque<int> q;
    for (int i = 0; i <= maxp; i++){
        while (!q.empty() && q.front() < i - as)
            q.pop_front();
        while (!q.empty() && dp[x - w - 1][q.back()] + (q.back() * ap) <= dp[x - w - 1][i] + (i * ap))
            q.pop_back();
        q.push_back(i);
        if (!q.empty())
            dp[x][i] = max(dp[x][i], dp[x - w - 1][q.front()] + (q.front() - i) * ap);
    }
    q = deque<int>();
    for (int i = maxp; i >= 0; i--) {
        while (!q.empty() && q.front() > i + bs)
            q.pop_front();
        while (!q.empty() && dp[x - w - 1][q.back()] + (q.back() * bp) <= dp[x - w - 1][i] + (i * bp))
            q.pop_back();
        q.push_back(i);
        if (!q.empty())
            dp[x][i] = max(dp[x][i], dp[x - w - 1][q.front()] + (q.front() - i) * bp);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> t >> maxp >> w;
    memset(dp, -0x3f, sizeof(dp));
    for (int i = 1; i <= t; i++){
        cin >> ap >> bp >> as >> bs;
        for (int j = 0; j <= as; j++)
            dp[i][j] = -j * ap;
        for (int j = 0; j <= maxp; j++)
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        if (i > w)
            DynalmicProgramming(i);
    }
    cout << dp[t][0];
    return 0;
}